package middleware

import (
	"time"

	"gitee.com/linxing_3/sr-core/plugins/log"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

func ApiRecordMW() gin.HandlerFunc {
	return func(c *gin.Context) {
		start := time.Now()
		c.Next()
		end := time.Now()
		spend := end.Sub(start)
		log.Debug("Api record",
			zap.String("path", c.Request.URL.Path),
			zap.String("method", c.Request.Method),
			zap.Duration("spend", spend),
			zap.Int("status", c.Writer.Status()),
		)
	}
}
